<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <a href="http://www.baidu.com">点击</a>
    <button>点击</button>
    <script>
      //   document.oncontextmenu = function () {
      //     console.log("点击了");
      //   };
      //   var btn = document.querySelector("button");
      //   btn.onclick = function () {
      //     window.location.href = "http://www.baidu.com";
      //   };
      var aEle = document.querySelector("a");
      aEle.onclick = function () {
        var res = confirm("是否要跳转？");
        if (res) {
          console.log("要跳转");
          window.location.href = "http://www.sohu.com";
        } else {
          console.log("不跳转");
        }

        return false;
      };
    </script>
  </body>
</html>
